home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / COSEmulator / COSEmulator- SRC / newmain.cp < prev    next >
Encoding:
Text File  |  1998-06-21  |  1.6 KB  |  73 lines  |  [TEXT/CWIE]

  1. #include "newmain.h"
  2. #include <devices.h>
  3.  
  4. static UInt8 Decimal2BCD(UInt8 n) {
  5.     return ((n / 10) << 4) + (n % 10); 
  6. }
  7.  
  8. static void Long2BCD(long blks, UInt8 *bcd) {
  9.     long     minutes, seconds, frames;
  10.  
  11.     blks += 150;
  12.     
  13.     minutes = blks / 4500L;
  14.     blks -= minutes * 4500L;
  15.     seconds = blks / 75L;
  16.     frames = blks - (seconds * 75);
  17.     
  18.     *bcd++ = Decimal2BCD((UInt8) minutes);
  19.     *bcd++ = Decimal2BCD((UInt8) seconds);
  20.     *bcd   = Decimal2BCD((UInt8) frames);
  21. }
  22.  
  23. static void Initialize(void){
  24.     /* Initialize all the needed managers. */
  25.     InitGraf(&qd.thePort);
  26.     InitFonts();
  27.     InitWindows();
  28.     InitMenus();
  29.     TEInit();
  30.     InitDialogs(nil);
  31.     InitCursor();
  32. }
  33.  
  34. static void clearmem(Ptr p,long l){
  35.     for (long a = 0;a<l;a++){
  36.         (p)[a] = 0;
  37.     }
  38. }
  39.  
  40. static OSErr AudioPlayTrack(short refNum,short track,Boolean isStopAddress){
  41.     
  42.     struct tAudioPlayParam {
  43.         short    addressType;
  44.         UInt8    address[4];
  45.         short    isStopAddress;
  46.         short    playMode;
  47.     };
  48.  
  49.     CntrlParam            cntrlParam;
  50.     tAudioPlayParam        &audioPlayParam = *(tAudioPlayParam *) cntrlParam.csParam;
  51.     
  52.     clearmem(Ptr(&cntrlParam), sizeof(CntrlParam));
  53.  
  54.     audioPlayParam.addressType = TRACKADDR;
  55.     audioPlayParam.address[3] = track;
  56.     audioPlayParam.isStopAddress = isStopAddress ? 1 : 0;
  57.     audioPlayParam.playMode = 9;    // Stereo
  58.     
  59.     cntrlParam.ioCRefNum = refNum;
  60.     cntrlParam.csCode = csAPlay;    // csAudioPlay
  61.  
  62.     OSErr err = PBControlSync((ParamBlockRec *) &cntrlParam);
  63.  
  64.     return err;
  65. }
  66.  
  67. void PlayTrack(short track){
  68.     short myRefNum;
  69.     OSErr myErr = OpenDriver("\p.AppleCD", &myRefNum);
  70.     myErr = AudioPlayTrack(myRefNum,track+1,true);
  71.     myErr = AudioPlayTrack(myRefNum,track,false);
  72. }
  73.